'use strict'

class media {

  constructor () {
    this.param = '/:type/:name'

    this.allowType = ['videos', 'images', 'audios']
  }

  /**
   * 获取资源具体内容
   * @param {context} c
   * @returns 
   */
  async get (c) {
    if (this.allowType.indexOf(c.param.type) < 0) return c.status(404).send('nothing')

    try {
      await c.helper.pipe(`${c.service.storageDir}/${c.param.type}/${c.param.name}`, c.reply)
    } catch (err) {
      return c.status(404)
    }
  }

}

module.exports = media
